Repository navigation
Conversation
Rolling back a failed operation unlinked each changed file and recreated it from its snapshot with shutil.copy2. The new file took the restoring user as owner and the directory's default permissions, which on Windows replaces a restricted file's access-control list with inherited entries. The journal now records the (st_dev, st_ino) of each regular file it snapshots. When that same file is still at the path, rollback opens it without truncating or following links, checks the opened file is the snapshotted one, then truncates it, writes the snapshot bytes back and restores mode and times with copystat. A file that was removed or replaced by another file, a symlink or a directory, or that cannot be opened for writing, is recreated as before. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
Rolling back a file in place set its mode and times with copystat after closing it, which follows a symlink swapped in at that path. Set them through the open descriptor where the platform supports it, open with O_NONBLOCK so a FIFO swapped in cannot block the open, and record a snapshotted file's identity only when it did not change while the snapshot was taken. Cover the fallback to recreating a file rollback cannot open, and check the upgrade rewrote the file before failing. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
There was a problem hiding this comment.
🟡 Changes recommended
Rollback can redirect metadata updates to an unintended file, leave extended attributes altered, and abandon remaining recovery steps after metadata permission errors.
4 open issues
What changed in this PR
Updates integration lifecycle rollback to restore individually snapshotted files in place, aiming to preserve file identity, ownership, hard links, and Windows access-control lists. This follows #5402 and supports the rollback requirements for #5117.
Changes:
- Record regular-file identities during snapshot creation.
- Restore matching files in place, with recreation as a fallback.
- Add regression coverage for rewritten files, replacements, and open failures.
Validation was limited to isolated standard-library checks; project tests and Windows validation were not run.
AI-generated review for the requester by GitHub Copilot (model: unknown; autonomous).
| File | Description |
|---|---|
tests/specify_cli/integrations/test_lifecycle.py |
Tests recreation after file replacement or an in-place open failure. |
tests/specify_cli/integrations/test_command_upgrade.py |
Tests rollback preserving a rewritten file’s identity, bytes, and mode. |
src/specify_cli/integrations/_lifecycle.py |
Records snapshot identities and adds in-place file restoration. |
Review effort: Max (adaptive)
|
Please address Copilot feedback |
…stores Restoring a file in place now restores its user extended attributes (where the os module has an API for them, which in CPython means Linux), times and mode only through the verified descriptor. Windows, which has no descriptor form of os.utime, sets them by path while the open handle still pins that file; any other platform without a descriptor form leaves them. A refused or unavailable metadata change no longer aborts rollback: the bytes stay restored, each remaining attribute, entry and directory cleanup still runs, and the file is reported with the recovery snapshots retained. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
|
@mnriem I've addressed the four Copilot threads in c3f7e18.
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Rollback can overwrite replacement files after inode reuse and leave unintended access ACLs in place while incorrectly reporting complete recovery.
5 open issues
Restore POSIX access ACLs during rollback · New Prevent inode reuse from misidentifying replacement files · New Preserve macOS BSD file flags during rollback · New Ensure the test exercises descriptor timestamp refusal handling · New Document partial recovery and directory restoration boundaries · New
4 resolved since last review
Review effort: Max (adaptive)
Rollback now holds a read-only descriptor on each file it may restore in place (outside Windows, up to a quarter of the open-file limit), so an original the operation unlinked cannot lend its inode to a replacement that the identity check would then accept. A file without a pin, or whose pinned inode has no name left, is recreated from its snapshot as before. Windows files are not pinned, since an open file there cannot be replaced. The Linux POSIX access ACL is now restored with the user extended attributes, and BSD file flags that differ after an in-place restore are reported as incomplete with the snapshots retained, as Python has no descriptor form of chflags(). The shared CLI and API references describe the in-place, recreated and partially restored outcomes. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
A Linux or macOS file past the pin limit is still recreated rather than restored in place, but when it is still the snapshotted inode at rollback, so was probably rewritten in place, it is now reported with the recovery snapshots retained rather than silently losing its owner and links. A file the operation is removing is neither pinned nor restored in place. The access ACL is restored after the user attributes, as a read-only ACL would refuse them, archive and compression flags the filesystem changes on a write are no longer compared, the incomplete-restore warning names ownership, links and file flags, and closing one pin can no longer leave the others open. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
|
@mnriem I've addressed the five Copilot threads from the last round in 108d3d0 and 60be027.
Testing:
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical rollback races can overwrite concurrently replaced files or delete recovery snapshots even when the pathname no longer points to the restored file.
4 open issues
5 resolved since last review
Review effort: Max (adaptive)
…firmed restores An original file is now pinned before it is snapshotted, and the snapshot is read through the pin, so a file unlinked and recreated in the gap cannot reuse the inode and be taken for the original. After restoring a file in place, rollback rechecks that the path still names the restored file; if it was removed or replaced during the copy, the restore is reported incomplete and the recovery snapshot kept, and the concurrent replacement is left alone. A verified original that cannot be opened for writing and is recreated is now reported with its snapshot retained, as an unpinned one already was, since recreation loses its owner, links and access-control list. Adds tests for the modification time restored on success, the pin taken before the snapshot, a path replaced during restore, and snapshot retention when the open is refused. Assisted-by: Claude Code (model: claude-sonnet-5-5, autonomous)
|
Review round summary, commit 452fb85. Four Copilot review threads addressed:
Verification: Posted on behalf of @echarrod by Claude Code (model: claude-sonnet-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical rollback defects can restore stale data and leave original contents or permissions unrecovered after path replacement, while warnings may incorrectly claim that contents were restored.
2 open issues
4 resolved since last review
Review effort: Max (adaptive)
|
Please address Copilot feedback |
… ACL-order test Patching os.listxattr also reordered shutil.copystat() when the journal snapshots the file. Python before 3.13 raises EACCES there once a read-only ACL is copied ahead of the user attributes, so the test failed on Python 3.11 before rollback ran. The test now reorders only what _restorable_xattrs() returns, which is what _restore_xattrs() sorts. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioAe4U3H3zhK3uAy6r
…removed parent A directory snapshotted after one of its journalled files was rewritten and then replaced read that file through its pin, so the snapshot held the old inode's bytes rather than the replacement. Rollback recreated the directory with those stale bytes, then reported the file as a conflict and left its original unrestored. A pin is now read only for the file's own first snapshot. The warning for an incomplete restore no longer says the contents came back: a path replaced while its bytes are restored still holds the replacement. It now says the file could not be fully restored, and the rollback docs say the same. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioAe4U3H3zhK3uAy6r
|
Review round summary for @mnriem. Head is now
Tests:
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed for unpublished concerns about rollback-test snapshot leaks and documentation that overstates in-place restoration guarantees.
No open issues 🎉
2 resolved since last review
Review effort: Max (adaptive)
|
Please address Copilot feedback |
…riptor test test_builtin_journal_never_writes_a_different_file_open_returned marks recovery incomplete, so rollback keeps its snapshot outside tmp_path and every run left a directory in the system temporary directory. The test now records the backup and removes it, as the other incomplete-recovery tests do. Assisted-by: Claude Code (model: claude-sonnet-5-5, autonomous) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioL9JfLpDRHzdjgcDf
|
Review round summary for @mnriem. Head is now
Tests: macOS, Posted on behalf of @echarrod by Claude Code (model: claude-sonnet-5-5), running autonomously; agent-written, no line-by-line human review. |



Description
Follow-up to #5402, and a prerequisite for #5117. When a built-in
initorupgradefails and the lifecycle journal rolls back,_restore_snapshots()deleted each snapshotted file and recreated it withshutil.copy2. The bytes came back, but a recreated file is a new file. On Windows it loses its access-control list and can inherit broader permissions from its directory. On POSIX it loses its owner and any hard links. Copilot raised this on #5117 (#5117 (comment)): itsopenai.yamlrewrite keeps the file's ACL in place, but a rollback through the journal would undo that.The journal now records each snapshotted file's identity (device and inode), but only when the file did not change while it was being snapshotted. On rollback, if that same file is still at the path, it is opened without following links (and without blocking on a FIFO). Rollback checks that it is still the same file, then writes the original bytes back in place. Mode and times are restored through the open descriptor, so a swapped-in symlink cannot redirect them. A file that was removed, replaced, or cannot be opened is recreated exactly as before.
Limit: files inside a snapshotted directory are still deleted and recreated. Only individually snapshotted files are restored in place.
Testing
test_builtin_upgrade_rollback_restores_a_rewritten_file_in_place(tests/specify_cli/integrations/test_command_upgrade.py) hard-links a customisedSKILL.md, then makesintegration upgrade --forcefail after the file has been rewritten. It checks that the original bytes and mode are back and that it is the same file. The test fails onmainand passes with this change.tests/specify_cli/integrations/test_lifecycle.pyadds two tests. A file that the operation replaced is recreated, not written through. A file that rollback cannot open falls back to being recreated.Full suite on macOS: 16801 passed, 616 skipped, 1 failed. The failure,
test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, also fails onmainlocally: the long venv path wraps in the output.uvx ruff@0.15.0 check src testsandgit diff --checkare clean.I could not test Windows ACLs directly. That they are kept follows from the file keeping its identity, which the tests check.
Tested locally with
.venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help)Ran relevant existing tests with
.venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
AI Disclosure
AI disclosure: Claude Code (model: claude-opus-5-5), running autonomously. The agent wrote the code, the tests and this description, and ran a
/code-reviewpass on the change. No line-by-line human review before opening.🤖 Generated with Claude Code
https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe